#include <Def.h>
#include "PushButton.h"

PushButton::PushButton(QWidget* parent):
QPushButton(parent)
{	
	status = ENTER;
	mMousePress = false;
}

PushButton::~PushButton()
{
}

void PushButton::loadPixmap(const QString& bitmap)
{
	mPixmap.load(bitmap);
	mWidth = mPixmap.width()/4;
	mHeight = mPixmap.height();
	setFixedSize(mWidth,mHeight);
}

void PushButton::enterEvent(QEvent* qet)
{
	status = ENTER;
	update();
}

void PushButton::mousePressEvent(QMouseEvent* qmt)
{
	if(qmt->button() == Qt::LeftButton)
	{
		mMousePress = true;
		status = PRESS;
		update();
	}
}

void PushButton::mouseReleaseEvent(QMouseEvent* qme)
{
	if(mMousePress)
	{
		mMousePress = false;
		status = ENTER;
		update();
		emit clicked();
	}
}

void PushButton::leaveEvent(QEvent* qet)
{
	status = ENTER;
	update();
}

void PushButton::paintEvent(QPaintEvent* qpe)
{
	QPainter painter(this);
	painter.drawPixmap(rect(),mPixmap.copy(mWidth*status,0,mWidth,mHeight));
}
